#include<iostream>
#include<cstring>
#include<string>
using namespace std;
int main()
{
	int n;
	string s;
	cin >> n >> s;
	while (n--) {
		int a;
		cin >> a;
		if (a == 1) {
			string t;
			cin >> t;
			s += t;
			cout << s << endl;
		}
		else if (a == 2) {
			int a, b;
			cin >> a >> b;
			s = s.substr(a, b);
			cout << s << endl;
		}
		else if (a == 3) {
			int a;
			string t;
			cin >> a >> t;
			s = s.insert(a, t);
			cout << s << endl;
		}
		else {
			string t;
			cin >> t;
			int a = s.find(t);
			cout << a << endl;
		}
    }
	return 0;
}